﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.Framework.Core.Common
{
    public class BaseService
    {
        /// <summary>
        /// 当前用户名
        /// </summary>
        protected long CurrentUserId
        {
            get
            {
                var userClaim = httpContextAccessor.HttpContext.User.Claims.FirstOrDefault(s => s.Type == "id");
                if (userClaim != null)
                {
                    return Convert.ToInt64(userClaim.Value);
                }
                return 0;
            }
        }
        /// <summary>
        /// 当前用户名
        /// </summary>
        protected string CurrentUserName
        {
            get
            {
                var userClaim = httpContextAccessor.HttpContext.User.Claims.FirstOrDefault(s => s.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");
                if (userClaim != null)
                {
                    return userClaim.Value;
                }
                return "";
            }
        }
        /// <summary>
        /// 
        /// </summary>
        protected readonly IHttpContextAccessor httpContextAccessor;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="httpContextAccessor"></param>
        public BaseService(IHttpContextAccessor httpContextAccessor)
        {
            this.httpContextAccessor = httpContextAccessor;
        }
    }
}
